<?php
require_once "config.php";
$offer_obj = new Offer();
$active_offers = $offer_obj->list_active_offers();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hotels With Offers</title>
<script language="Javascript" type="text/javascript" src="js/jquery-1.4.1.js"></script>
<script language="Javascript" type="text/javascript" src="js/jquery.lwtCountdown-1.0.js"></script>
<script language="Javascript" type="text/javascript" src="js/misc.js"></script>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
<?php require_once 'top_header.php'; ?>
    
<div class="contentPane">
  <div id="sidebar">
    <span class="menu"><img src="images/call.png" alt="Advertise with Hotel with Offers" class="callus"  /></span>
    <div class="joinus">
      <h1>INVITE A FRIEND</h1>
      <h2>Tell a friend and win Rs100.00</h2>
      <div class="joinbtn"><a href="#">LEARN&nbsp;MORE</a></div>
     </div>
    <div class="reserve"><span class="reserveitem">Reserved for :</span> <span class="reserveitem">advertising</span> <span class="reserveitem">latest news</span> <span class="reserveitem">soon ending deals &amp; offers</span></div>
  </div>
  <div class="leftPane">
      <div class="mainMenu"><?php require_once 'main_menu.php'; ?></div>
    <?php require_once 'newsletter_plug.php'; ?>
    <div id="Listings">
        <?php
        if(!empty($active_offers)) {
            $now = time();
           
            $j =1;
            foreach ($active_offers as $active_offer) {
               $you_saved = $active_offer['regular_amount'] - $active_offer['discount_amount'];
               $discount_percentage = ceil((($active_offer['regular_amount'] - $active_offer['discount_amount'])/$active_offer['regular_amount'])*100);
               $item_sold = $offer_obj->get_noof_sold_items($active_offer['offer_id']);
             
               $offer_hour = substr($active_offer['offer_end_date'], 11, 2) ;
               $offer_min =  substr($active_offer['offer_end_date'], 14, 2);
               $offer_sec =  substr($active_offer['offer_end_date'], 17, 2);
               $offer_day =  substr($active_offer['offer_end_date'], 8, 2);
               $offer_month =  substr($active_offer['offer_end_date'], 5, 2);
               $offer_year =  substr($active_offer['offer_end_date'], 0, 4);
             $target = mktime(
		$offer_hour,
		$offer_min,
		$offer_sec,
		$offer_month,
		$offer_day,
		$offer_year
	);
            $diffSecs = $target - $now;
            if($diffSecs <= 0) {
                continue;
            }
	$date = array();
	$date['secs'] = $diffSecs % 60;
	$date['mins'] = floor($diffSecs/60)%60;
	$date['hours'] = floor($diffSecs/60/60)%24;
	$date['days'] = floor($diffSecs/60/60/24)%7;
	$date['weeks']	= floor($diffSecs/60/60/24/7);

	foreach ($date as $i => $d) {
		$d1 = $d%10;
		$d2 = ($d-$d1) / 10;
		$date[$i] = array(
			(int)$d2,
			(int)$d1,
			(int)$d
		);
	}
               

?>
      <div class="item">
        <div class="content">
          <div class="imageHolder">
            <div class="corners"></div>
            <img src="images/sample_image.jpg" width="282" height="196" alt="Hotel with Offers" /></div>
          <div class="intro">
              <div class="introUpper">
                <h1><?=$active_offer['offer_title'];?></h1>
                <div class="socialNetworkWidgets">Social Network Widgets Here
                <a href="#" class="emailaFriend">Email a Friend</a>
                <div class="clear"></div>
                </div>
                <h2 class="description"><?=$active_offer['offer_overview']?>. ...</h2>
              </div>
              <div class="introLower">
                <div class="actions">
                  <div class="pricing">
                    <ul>
                      <li class="normalPrice"><em>Normal Price</em><br /> 
                        $<?=$active_offer['regular_amount']?></li>
                      <li><em>You Save</em><br />$<?=$you_saved?></li>
                    </ul>
                  </div>
                  <div class="callToAction">
                    <div class="moreInfo"><a href="#">more info</a></div>
                  	<div class="buyNow"><a href="#"><img src="images/button_buynow.png" alt="Hotel with Offers | Buy Now" width="108" height="37" border="0" /></a></div>
                  </div>
                  
                </div>
                <div class="price currencyUSD">
                  <h1><a href="#"><?=$discount_percentage?>% OFF</a></h1>
                  <h2><a href="#"><strong>$</strong><?=$active_offer['discount_amount'];?></a></h2>
                  <h3><a href="#"><?=$item_sold?> SOLD</a></h3>
                </div>
              </div>
          </div>
</div>
        <div class="footer">
          <div class="countdown">Offer ends in<br />
           <div id="countdown_dashboard<?=$j?>">
			

			<div class="dash days_dash">
				<span class="dash_title">days</span>
				<div class="digit"><?=$date['days'][0]?></div>
				<div class="digit"><?=$date['days'][1]?></div>
			</div>

			<div class="dash hours_dash">
				<span class="dash_title">hours</span>
				<div class="digit"><?=$date['hours'][0]?></div>
				<div class="digit"><?=$date['hours'][1]?></div>
			</div>

			<div class="dash minutes_dash">
				<span class="dash_title">minutes</span>
				<div class="digit"><?=$date['mins'][0]?></div>
				<div class="digit"><?=$date['mins'][1]?></div>
			</div>

			<div class="dash seconds_dash">
				<span class="dash_title">seconds</span>
				<div class="digit"><?=$date['secs'][0]?></div>
				<div class="digit"><?=$date['secs'][1]?></div>
			</div>

		</div></div>
          <div class="askQuestion"><a href="#">Ask a question about this offer</a></div>
        </div>
      </div>
      <?php
      $j++;
            }

        }
        ?>

     
    </div>
    <div class="clear"></div>
</div>
</div>
<div class="clear"></div>
</div>
<div id="footerWrapper">
<?php require_once 'footer.php'; ?>
</div>
    <script language="javascript" type="text/javascript">
			jQuery(document).ready(function() {
                            <?php $k = 1;
                                foreach ($active_offers as $active_offer) {
                                    $offer_hour = substr($active_offer['offer_end_date'], 11, 2) ;
               $offer_min =  substr($active_offer['offer_end_date'], 14, 2);
               $offer_sec =  substr($active_offer['offer_end_date'], 17, 2);
               $offer_day =  substr($active_offer['offer_end_date'], 8, 2);
               $offer_month =  substr($active_offer['offer_end_date'], 5, 2);
               $offer_year =  substr($active_offer['offer_end_date'], 0, 4);

                            ?>
				$('#countdown_dashboard<?=$k?>').countDown({
					targetDate: {
						'day': 		<?=$offer_day?>,
						'month': 	<?=$offer_month?>,
						'year': 	<?=$offer_year?>,
						'hour': 	<?=$offer_hour?>,
						'min': 		<?=$offer_min?>,
						'sec': 		<?=$offer_sec?>
					}
				});
                                

				<?php $k++; } ?>

			});
		</script>
</body>
</html>
